extends CharacterBody2D
@onready var animation_tree: AnimationTree = $AnimationTree
@export var speed := 100.0
var is_moving := false
var direction:Vector2 = Vector2.ZERO
func get_input():
	# 速度归一化，防止同时按住两个方向，速度变快
	direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
	velocity = direction.normalized() * speed
	if direction != Vector2.ZERO:
		set_run(true)
		update_blend_position()
	else:
		set_run(false)
		
func set_run(val):
	animation_tree.set('parameters/conditions/is_run', val)
	animation_tree.set('parameters/conditions/is_idle', !val)

func update_blend_position():
	animation_tree.set('parameters/Idle/blend_position', direction)
	animation_tree.set('parameters/Run/blend_position', direction)

func _physics_process(delta):
	get_input()
	move_and_slide()
	
	
